using UnityEngine;
using System.Collections;

public class ControlScript : AbstractMenuScript {
	
	//public GameOption ;
	public MenuKeyListener _keyListener;
	public ControlType _controlType;
	public ControlSceme _controlSceme;
	
	private SimpleMenuItem _menuItem;
	//private SelectionMenu _menu;
	
	void Start() {
		_menuItem = gameObject.GetComponent<SimpleMenuItem>();
		
		switch (_controlType) {
			
			case ControlType.Up:
					_menuItem._text = _controlSceme._up.ToString();
				break;
			case ControlType.Down:
					_menuItem._text = _controlSceme._down.ToString();
				break;
			case ControlType.Left:
					_menuItem._text = _controlSceme._left.ToString();
				break;
			case ControlType.Right:
					_menuItem._text = _controlSceme._right.ToString();
				break;
			case ControlType.Space:
					_menuItem._text = _controlSceme._space.ToString();
				break;			
			case ControlType.Jump:
					_menuItem._text = _controlSceme._jump.ToString();
				break;	
			}
	}
	
	public override void Run(KeyCode k){		
		
		if (_menuItem._active) {
			
			switch (_controlType) {
			
			case ControlType.Up:
				_controlSceme._up = k;
				break;
			case ControlType.Down:
				_controlSceme._down = k;
				break;
			case ControlType.Left:
					_controlSceme._left = k;
				break;
			case ControlType.Right:
					_controlSceme._right = k;
				break;
			case ControlType.Space:
				_controlSceme._space = k;
				break;
			case ControlType.Jump:
					_controlSceme._jump = k;
				break;	
			}
			_menuItem._active = false;
			_keyListener.ActiveMenu = _menuItem.Menu;
			_menuItem._text = k.ToString();
			
			
		} else {
			_menuItem._text = "[ ]";
			_menuItem._active = true;
			_keyListener.ActiveMenu = _menuItem;
		}
	}
	
}
